package com.hxkcloud.nurse.activitys;


import android.os.Bundle;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.CodeImageBean;
import com.hxkcloud.nurse.beans.resultbeans.ObjectResultBean;
import com.hxkcloud.nurse.config.UrlConfig;
import com.hxkcloud.nurse.request.MessageCode;
import com.hxkcloud.nurse.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.nurse.utils.ImageOptionUtils;
import com.hxkcloud.nurse.views.CircleImageView;

/**
 * Created by ray_lei on 2016/7/10.
 */
public class ScanCodeActivity extends BaseActivity implements View.OnClickListener {

    private LinearLayout ll_title;
    private ImageView iv_back;
    private TextView tv_title;
    private CircleImageView iv_head;
    private TextView tv_name;
    private ImageView iv_qrcode;

    private ObjectResultBean<CodeImageBean> resultBean;

    private String imageUrl = "";

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.NETWORKCODE_MYQRCODEIMAGE_SUCCESS:
                if (msg.obj != null) {
                    resultBean = (ObjectResultBean<CodeImageBean>) msg.obj;
                    if (resultBean.getData() != null) {
                        imageUrl = resultBean.getData().getQRCodeImage();
                        imageLoader.displayImage(UrlConfig.image_host + imageUrl, iv_qrcode, ImageOptionUtils.getInstance().getSimplePicOptions());
                    }

                }

                break;
            case MessageCode.NETWORKCODE_MYQRCODEIMAGE_FAILURE:
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }

                break;

        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_scancode);
        initView();
        initData();
        initListener();
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);

        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        tv_title.setText(getResources().getText(R.string.mine_text_erweima));
        iv_back.setOnClickListener(this);

        iv_head = (CircleImageView) findViewById(R.id.scancode_ci_icon);
        tv_name = (TextView) findViewById(R.id.scancode_name);
        iv_qrcode = (ImageView) findViewById(R.id.scancode_qrcode);

        LinearLayout.LayoutParams lp_qrcode = new LinearLayout.LayoutParams(screenWidth / 2, screenWidth / 2);
        lp_qrcode.gravity = Gravity.CENTER_HORIZONTAL;
        iv_qrcode.setLayoutParams(lp_qrcode);

        imageLoader.displayImage(loginInfo.getHeadImg(), iv_head, ImageOptionUtils.getInstance().getNurseHeadOptions());
        tv_name.setText(loginInfo.getName());


    }

    @Override
    protected void initListener() {
        iv_back.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        loading();
        YiJiaHuNetWorkUtils.myQrcodeImage(handler);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_back://back
                finish();
                break;
        }
    }
}
